package pl.bizuteria.sklep.api.product;


import com.google.web.bindery.requestfactory.shared.Locator;

public class ProductLocator extends Locator<Product, Long> {
	
	ICommonService commonService;
	
	
	public ProductLocator(ICommonService commonService) {
		this.commonService = commonService;
	}

	@Override
	public Product create(Class<? extends Product> clazz) {
		try {
//			System.out.println("entitylocator");
//			System.out.println(clazz);
			Product newInstance = clazz.newInstance();
//			System.out.println("stworzony!!!");
			return newInstance;
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		}
//		System.out.println("returning null....");
		return null;
	}

	@Override
	public Product find(Class<? extends Product> clazz, Long id) {
		return commonService.find(clazz, id);
	}


	@Override
	public Class<Product> getDomainType() {
//		System.out.println("getdomain type");
		throw new UnsupportedOperationException();
	}

	@Override
	public Long getId(Product domainObject) {
//		System.out.println("get id");
		return domainObject.getId();
	}

	@Override
	public Class<Long> getIdType() {
//		System.out.println("gtet id type");
		return Long.class;
	}

	@Override
	public Object getVersion(Product domainObject) {
//		System.out.println("get version");
		return domainObject.getVersion();
	}

}
